Repository navigation
feat(pm-stack): persist canonical C7 reports - #12364
Conversation
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 16 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2e15388c74
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| test("uses calendar boundaries across daylight-saving transitions", () => { | ||
| const spring = dailyReportPeriod("2026-03-08"); |
There was a problem hiding this comment.
Add generated coverage for the calendar-boundary invariants
The new suite covers only hand-picked dates, but this calendar conversion has meaningful invariants that the repository's testing doctrine requires property-based tests to cover; example-based acceptance tests do not replace that coverage. Add generated dates over a documented supported range and verify that boundaries round-trip to Chicago midnight, adjacent periods meet exactly, and soft close round-trips to next-day 08:00, using a named invariant or model oracle. This also covers periods immediately before DST transitions, where the offset changes between midnight and soft close.
AGENTS.md reference: AGENTS.md:L36-L39
Useful? React with 👍 / 👎.
|
Progress update for task 21000 / #12349:
This is a reviewable partial slice, not full C7 completion: the repository does not expose the designed fleet KV append families or a selected fleet-wide permanent-store adapter, and weekly/other grains plus generation commands remain future work. Those gaps are documented in |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a4c91e31d4
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| record, | ||
| ts: record.generatedAt, | ||
| }; | ||
| await appendFile(file, `${JSON.stringify(event)}\n`, "utf8"); |
There was a problem hiding this comment.
Separate new events from a torn trailing log entry
If an interrupted write leaves an incomplete final JSONL entry without a newline, readEvents ignores that fragment, but this append concatenates the new event directly onto it. The call returns inserted: true, yet subsequent reads discard the combined invalid line, silently losing the newly acknowledged record. The snapshot append has the same problem. Recover or terminate a torn trailing entry before appending another event.
Useful? React with 👍 / 👎.
| const events = await readEvents(file); | ||
| const existing = events.find((event) => event.type === "report.snapshot" && event.snapshot?.id === snapshot.id)?.snapshot; |
There was a problem hiding this comment.
Reject snapshots that conflict with an existing generation
If a generation has already been stored, a caller can rebuild its input with changed block text but the same period/template/cursor and successfully create the first snapshot from that conflicting record. assertCanonicalRecord accepts both because their IDs depend only on the key, and this lookup checks only existing snapshots. The log then contains different content under the same report-record ID, despite appendReportRecord rejecting that exact conflict. Compare the snapshot source against any stored generation with its ID before freezing it.
Useful? React with 👍 / 👎.
|
Follow-up for task 21000: hardened the C7 append path against torn trailing JSONL writes (new record and snapshot appends remain readable), reject snapshots whose canonical source conflicts with an already stored generation, and added deterministic generated-date coverage for Chicago-midnight adjacency and next-day 08:00 soft close. Verified on the laptop at d0b2def: |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d0b2def6a5
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| assertCanonicalRecord(record); | ||
| return serializeAppend(file, async () => { | ||
| const events = await readEvents(file); | ||
| const existing = events.find((event) => event.type === "report.generated" && event.record?.id === record.id)?.record; |
There was a problem hiding this comment.
Check frozen snapshots before accepting a generation
If a caller freezes a record before appending its generation, then appends changed block text with the same period/template/cursor, this lookup finds no generation and accepts the conflicting record. The log consequently exposes different content under the same report-record ID through readReportSnapshots and readReportRecords. The new generation check in appendReportSnapshot protects only the opposite call order; standalone snapshots are still accepted. Compare against snapshot records with the same report-record ID here as well, or require the matching generation to exist before freezing.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 176c723b97
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| return `{${Object.keys(object).sort().map((key) => `${JSON.stringify(key)}:${canonicalJson(object[key])}`).join(",")}}`; | ||
| } | ||
| return JSON.stringify(value) ?? "null"; |
There was a problem hiding this comment.
Match JSON serialization when comparing optional properties
When a valid block contains links: undefined, the first append succeeds, but an identical rerun throws ReportRecordConflictError. JSON serialization omits that optional property from the stored event, whereas canonicalJson retains it as "links":null, so the persisted record and the unchanged input compare differently. Omit undefined object properties during canonicalization, or normalize records to their persisted JSON representation before comparison, to preserve the documented idempotency contract.
Useful? React with 👍 / 👎.
| if (snapshot.record.period.id !== record.period.id) throw new Error("correction period must match the snapshot"); | ||
| correction.originalRecordId = snapshot.reportRecordId; | ||
| const existing = events.find((event) => event.type === "report.snapshot-correction" && event.correction?.id === correction.id)?.correction; |
There was a problem hiding this comment.
Reject correction content that conflicts with a stored record ID
After storing a generation and its snapshot, a caller can build changed block text with the original period/template/cursor and pass it to appendReportSnapshotCorrection. This checks only existing correction IDs, so the first correction succeeds even though its embedded record has the original generation's ID with different content; readReportRecords and readReportSnapshotCorrections then expose contradictory payloads for that ID. Check the correction source against stored generations and the frozen snapshot, rejecting conflicting content unless it uses a new record key.
Useful? React with 👍 / 👎.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2b79ec3e81
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| assertRecordIdContent(await readLocationEvents(location), record); | ||
| const result = await appendDocumentEvent(location, event); |
There was a problem hiding this comment.
Enforce record-content consistency atomically across event types
When a generation and a snapshot containing different content for the same record ID are appended concurrently to the remote backend, both can pass assertRecordIdContent before either insert completes. Their document keys differ by event type, so both inserts succeed, leaving contradictory payloads under one report-record ID. Fresh evidence: running these calls together with Promise.all returned inserted: true for both, and subsequent reads exposed different block text in the generation and snapshot. The sequential checks fix the previously reported call-order cases but not this race; enforce a shared, atomic content claim per record ID before accepting generation, snapshot, or correction events.
Useful? React with 👍 / 👎.
|
|
||
| /** Build a validated canonical record; generatedAt is injectable for replay. */ |
There was a problem hiding this comment.
Encode the record identity tuple without delimiter ambiguity
If templateVersion or sourceCursor contains a newline, distinct accepted identity tuples can produce the same hash input. For example, (templateVersion: "daily-v1\nsource", sourceCursor: "cursor") and (templateVersion: "daily-v1", sourceCursor: "source\ncursor") produce identical record IDs for the same period. Both pass makeReportRecord validation, but after persisting one, appending the other raises a content conflict instead of retaining the distinct report version. Serialize the tuple unambiguously, such as with a JSON array, or reject delimiter characters before constructing the key.
Useful? React with 👍 / 👎.
|
@codex review |
|
To use Codex here, create a Codex account and connect to github. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a7f33fbb31
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| describe("C7 canonical report records", () => { | ||
| test("persists provenance and cursor and makes a rerun a no-op", async () => { |
There was a problem hiding this comment.
Generate coverage for canonical record persistence invariants
The new record suite uses only hand-picked examples, although stable identity encoding, JSON round-trip idempotency, and immutable content across event types are meaningful invariants covered by the repository's mandatory property/model-based testing doctrine. The generated calendar tests do not exercise these persistence invariants. Add generated valid records and append-operation sequences, using named invariant or model oracles to verify distinct identity tuples, idempotent retries after serialization, and cross-event content consistency.
AGENTS.md reference: AGENTS.md:L37-L39
Useful? React with 👍 / 👎.
Summary
Implement C7 canonical report records and durable append through the existing
public.agg_store_documentsKV table. This closes the acceptance in #12349 without adding a parallel report database or dual-writing stores.Verification
bun run typecheck— passed.bun test test/report-records-c7.test.ts test/report-periods-c7.test.ts test/turso-stores.test.ts— 22 passed, 0 failed, 2,154 assertions.bun run contract:checkandbun run provenance:check— passed.git diff --check— passed.Merge Danger
Door: two-way. Blast radius: additive report records and new namespaced rows in the existing document table. No existing documents are rewritten by C7 append calls.
Closes #12349.